/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.prod;

import dp1.titandevelop.titano.persistent.Producto;
import dp1.titandevelop.titano.persistent.Receta;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;


/**
 *
 * @author andres
 */
public class ModulosT_PRO_DetalleReceta extends javax.swing.JInternalFrame {

  // private Producto producto;
    private ArrayList<Receta> listaReceta;
 //    private ArrayList<Producto> listaInsumos;
     
    ModulosT_PRO_DetalleReceta.ModeloInsumosBD modeloInsumosBD = new ModulosT_PRO_DetalleReceta.ModeloInsumosBD();
 
    //Refrescar la tabla de productos
    public void RefrescarTabla() {
        AbstractTableModel aux = (AbstractTableModel) tblReceta.getModel();
        aux.fireTableDataChanged();
    }
    
    
      
    class ModeloInsumosBD extends AbstractTableModel { // usando una clase anonima
        // colocando los titulos de las columnas

        String[] titles = {"Insumo", "Cantidad", "UM"};

        public String getColumnName(int col) {
            return titles[col];
        }

        public int getRowCount() {
            return listaReceta.size(); // cuantos registros (filas)
        }

        public int getColumnCount() {
            return 3; // cuantas columnas
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            String res = null;
            Receta r = listaReceta.get(rowIndex);
            switch (columnIndex) {
                case 0:
                    res =r.getToProducto().getDescripcion();
                    break;
                case 1:
                    res = r.getCantidad().toString();
                    break;
                case 2:
                    res = r.getUm();
                    break;
                            }
            return res;
        }

        public Receta getValue(int row) {
            return listaReceta.get(row);
        }

        
    };
 
    
    public ModulosT_PRO_DetalleReceta(ArrayList<Receta> l) {       
      initComponents();
      listaReceta=new ArrayList<Receta>();
      listaReceta =l;
     
      this.tblReceta.setModel(this.modeloInsumosBD);
      
    }    
    
  

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblReceta = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();

        setResizable(true);
        setTitle("Escoger una Orden de Producción");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Detalle de Receta"));

        tblReceta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblReceta.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblRecetaMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblReceta);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 696, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                .addContainerGap())
        );

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/retroceder.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(jButton2)
                .addGap(8, 8, 8))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblRecetaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblRecetaMouseClicked
        // TODO add your handling code here:
      
    }//GEN-LAST:event_tblRecetaMouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblReceta;
    // End of variables declaration//GEN-END:variables

    
}
